package model

import "gorm.io/gorm"

type User struct {
	gorm.Model
	UserID   string
	UserName string
	IsReady  bool   `json:"is_ready"` // 准备状态
	RoomID   string `json:"room_id"`  // 当前所在房间ID
}

// 更新用户准备状态
func UpdateUserReadyStatus(db *gorm.DB, userID string, roomID string, isReady bool) error {
	return db.Model(&User{}).Where("user_id = ?", userID).Updates(map[string]interface{}{
		"is_ready": isReady,
		"room_id":  roomID,
	}).Error
}

// 获取房间内所有用户准备状态
func GetRoomUsersReadyStatus(db *gorm.DB, roomID string) ([]User, error) {
	var users []User
	err := db.Where("room_id = ?", roomID).Find(&users).Error
	return users, err
}

// 获取用户准备状态
func GetUserReadyStatus(db *gorm.DB, userID string) (bool, error) {
	var user User
	err := db.Where("user_id = ?", userID).First(&user).Error
	return user.IsReady, err
}
